// js/main.js

function login(event) {
    event.preventDefault();

    const username = document.getElementById("username").value;
    const password = document.getElementById("password").value;

    fetch('/api/team/login', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: `username=${username}&password=${password}`
    })
        .then(response => response.json())
        .then(data => {
            const messageElem = document.getElementById("message");
            if (data.success) {
                messageElem.textContent = "登录成功！跳转中...";
                window.location.href = 'members.html';
            } else {
                messageElem.textContent = "登录失败：" + data.message;
            }
        })
        .catch(error => console.error("登录错误:", error));
}
